/**
 * Created by hc on 2016/7/13.
 */
(function (main) {
    var AddressAdd = {};

    AddressAdd.bindEvent = function(){
        $("#btn_addAddress").click(function(){
            var condition = $("#basic_validate").serialize();
            condition += "&consignee_province=" + $("#ssl_province").find("option:selected").text();
            condition += "&consignee_city=" + $("#ssl_city").find("option:selected").text();
            condition += "&consignee_district=" + $("#ssl_district").find("option:selected").text();
            $.ajax({
                type: 'post',
                url: '/AjaxService/center/address/saveorupdate',
                data: condition,
                dataType: 'json',
                async: false,
                success: function (data) {
                    if (data.IsSuccess == 0) {
                        alert(data.ErrorMsg);
                        return;
                    } else {
                        alert('操作成功');
                    }
                },
                error: function (e, err_name, err_text) {

                }
            });

        });
        
        var address_user_id = $('#address_user_id').val();
        
        $("#goToOrderCart").click(function(){
        	var dealer_channel=$('#dealer_channel').val();
        	if(dealer_channel ==1 ){
        	window.location.href = '/Dealer/dealerOrderCart?address_user_id='+address_user_id;
        	}
        	if(dealer_channel == 2){
        		window.location.href = '/VRDealer/dealerOrderCart?address_user_id='+address_user_id;	
        	}
        	if(dealer_channel == 3){
        		window.location.href = '/STDealer/dealerOrderCart?address_user_id='+address_user_id;	
        	}
        });
        
    }

    $(document).ready(function () {
        CommonPage.InitRegion();
        AddressAdd.bindEvent();

        //设置UserId的可编辑状态,如果有值那么设置成readonly
        if($("#address_user_id").val()){
            $("#address_user_id").attr("readonly","readonly");
        }

        //设置省市区
        if($("#temp_province").val()){
            $('#ssl_province').val($("#temp_province").val());
            $('#ssl_province').trigger('change');
        }
        if($("#temp_city").val()){
            $('#ssl_city').val($("#temp_city").val());
            $('#ssl_city').trigger('change');
        }
        if($("#temp_district").val()){
            $('#ssl_district').val($("#temp_district").val());
            $('#ssl_district').trigger('change');
        }


    });
})(window);